﻿using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace BookShop
{
    /// <summary>
    /// Controller class for Book
    /// </summary>
    public partial class BookController
    {
        public DataSet GetBookInfo(int startRowIndex, int maximumRows)
        {
            int currentPage = startRowIndex / maximumRows + 1;
            DataSet book = new Select(Book.IsbnColumn, Book.BookNameColumn, Book.AuthorColumn, Book.PublisherColumn, Book.PriceColumn, Category.NameColumn)
                .From<Book>().InnerJoin(Category.CategoryIDColumn, Book.CategoryIDColumn)
                .Paged(currentPage, maximumRows).ExecuteDataSet();
            return book;
        }
        public int GetBookCount()
        {
            return new Select().From<Book>().GetRecordCount();
        }

        public void Update(string Isbn, string BookName, string Author)
        {
            //new BookController().Update(Isbn, BookName, Author, Publisher, Price, CategoryID, Description);
            //Book book = new Book("isbn",Isbn);
            //book.Isbn = Isbn;
            Book book = new Book();
            book.MarkOld();
            book.IsLoaded = true;
            book.Isbn = Isbn;
            book.BookName = BookName;
            if (Author != null)
                book.Author = Author;
            book.Save();
        }
    }
}